from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-10-01 14:05:21.615344
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 01, Oct, 2022
Time: 14:05:30
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -50.5679
Nobs: 796.000 HQIC: -50.8937
Log likelihood: 10261.3 FPE: 6.43965e-23
AIC: -51.0970 Det(Omega_mle): 5.75525e-23
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.299056 0.053117 5.630 0.000
L1.Burgenland 0.108681 0.035671 3.047 0.002
L1.Kärnten -0.106481 0.018982 -5.609 0.000
L1.Niederösterreich 0.209099 0.074570 2.804 0.005
L1.Oberösterreich 0.101574 0.071618 1.418 0.156
L1.Salzburg 0.252509 0.038042 6.638 0.000
L1.Steiermark 0.037338 0.049767 0.750 0.453
L1.Tirol 0.106462 0.040335 2.639 0.008
L1.Vorarlberg -0.059077 0.034679 -1.704 0.088
L1.Wien 0.055222 0.063991 0.863 0.388
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.063459 0.110055 0.577 0.564
L1.Burgenland -0.033385 0.073907 -0.452 0.651
L1.Kärnten 0.047796 0.039330 1.215 0.224
L1.Niederösterreich -0.171356 0.154504 -1.109 0.267
L1.Oberösterreich 0.384410 0.148387 2.591 0.010
L1.Salzburg 0.287861 0.078821 3.652 0.000
L1.Steiermark 0.106384 0.103112 1.032 0.302
L1.Tirol 0.313657 0.083571 3.753 0.000
L1.Vorarlberg 0.025059 0.071853 0.349 0.727
L1.Wien -0.017186 0.132583 -0.130 0.897
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.190245 0.027289 6.971 0.000
L1.Burgenland 0.090047 0.018326 4.914 0.000
L1.Kärnten -0.008457 0.009752 -0.867 0.386
L1.Niederösterreich 0.264111 0.038311 6.894 0.000
L1.Oberösterreich 0.126786 0.036794 3.446 0.001
L1.Salzburg 0.047668 0.019544 2.439 0.015
L1.Steiermark 0.016705 0.025568 0.653 0.514
L1.Tirol 0.094273 0.020722 4.549 0.000
L1.Vorarlberg 0.059287 0.017817 3.328 0.001
L1.Wien 0.120372 0.032875 3.661 0.000
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.108958 0.027945 3.899 0.000
L1.Burgenland 0.044591 0.018766 2.376 0.017
L1.Kärnten -0.016109 0.009986 -1.613 0.107
L1.Niederösterreich 0.193686 0.039231 4.937 0.000
L1.Oberösterreich 0.293503 0.037678 7.790 0.000
L1.Salzburg 0.115229 0.020014 5.757 0.000
L1.Steiermark 0.100171 0.026182 3.826 0.000
L1.Tirol 0.116257 0.021220 5.479 0.000
L1.Vorarlberg 0.070754 0.018245 3.878 0.000
L1.Wien -0.027318 0.033665 -0.811 0.417
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.128510 0.050662 2.537 0.011
L1.Burgenland -0.051436 0.034022 -1.512 0.131
L1.Kärnten -0.040186 0.018105 -2.220 0.026
L1.Niederösterreich 0.171145 0.071123 2.406 0.016
L1.Oberösterreich 0.138496 0.068308 2.028 0.043
L1.Salzburg 0.286090 0.036284 7.885 0.000
L1.Steiermark 0.034274 0.047466 0.722 0.470
L1.Tirol 0.163784 0.038471 4.257 0.000
L1.Vorarlberg 0.104066 0.033076 3.146 0.002
L1.Wien 0.067583 0.061033 1.107 0.268
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059962 0.040188 1.492 0.136
L1.Burgenland 0.038303 0.026988 1.419 0.156
L1.Kärnten 0.050601 0.014362 3.523 0.000
L1.Niederösterreich 0.225364 0.056418 3.995 0.000
L1.Oberösterreich 0.281842 0.054185 5.201 0.000
L1.Salzburg 0.050840 0.028782 1.766 0.077
L1.Steiermark -0.006554 0.037652 -0.174 0.862
L1.Tirol 0.149950 0.030517 4.914 0.000
L1.Vorarlberg 0.071285 0.026238 2.717 0.007
L1.Wien 0.079354 0.048414 1.639 0.101
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.178719 0.048044 3.720 0.000
L1.Burgenland -0.005815 0.032264 -0.180 0.857
L1.Kärnten -0.061119 0.017169 -3.560 0.000
L1.Niederösterreich -0.083404 0.067448 -1.237 0.216
L1.Oberösterreich 0.192361 0.064778 2.970 0.003
L1.Salzburg 0.056957 0.034409 1.655 0.098
L1.Steiermark 0.230758 0.045013 5.126 0.000
L1.Tirol 0.493703 0.036483 13.533 0.000
L1.Vorarlberg 0.049473 0.031367 1.577 0.115
L1.Wien -0.049272 0.057879 -0.851 0.395
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161178 0.055166 2.922 0.003
L1.Burgenland -0.010961 0.037046 -0.296 0.767
L1.Kärnten 0.066002 0.019714 3.348 0.001
L1.Niederösterreich 0.200892 0.077446 2.594 0.009
L1.Oberösterreich -0.061588 0.074380 -0.828 0.408
L1.Salzburg 0.215459 0.039509 5.453 0.000
L1.Steiermark 0.113902 0.051686 2.204 0.028
L1.Tirol 0.076620 0.041890 1.829 0.067
L1.Vorarlberg 0.124516 0.036017 3.457 0.001
L1.Wien 0.116171 0.066458 1.748 0.080
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.355460 0.032052 11.090 0.000
L1.Burgenland 0.005962 0.021524 0.277 0.782
L1.Kärnten -0.023567 0.011454 -2.058 0.040
L1.Niederösterreich 0.223212 0.044996 4.961 0.000
L1.Oberösterreich 0.176151 0.043215 4.076 0.000
L1.Salzburg 0.047149 0.022955 2.054 0.040
L1.Steiermark -0.018463 0.030030 -0.615 0.539
L1.Tirol 0.108737 0.024339 4.468 0.000
L1.Vorarlberg 0.073383 0.020926 3.507 0.000
L1.Wien 0.053199 0.038613 1.378 0.168
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.041131 0.152011 0.191395 0.157167 0.125071 0.113281 0.065961 0.225697
Kärnten 0.041131 1.000000 -0.002574 0.129637 0.041347 0.096135 0.429742 -0.053143 0.101653
Niederösterreich 0.152011 -0.002574 1.000000 0.337532 0.154935 0.300667 0.110682 0.183615 0.327360
Oberösterreich 0.191395 0.129637 0.337532 1.000000 0.232232 0.333483 0.172714 0.172391 0.264593
Salzburg 0.157167 0.041347 0.154935 0.232232 1.000000 0.146276 0.126526 0.149026 0.136704
Steiermark 0.125071 0.096135 0.300667 0.333483 0.146276 1.000000 0.153095 0.140811 0.080702
Tirol 0.113281 0.429742 0.110682 0.172714 0.126526 0.153095 1.000000 0.114832 0.154987
Vorarlberg 0.065961 -0.053143 0.183615 0.172391 0.149026 0.140811 0.114832 1.000000 0.007247
Wien 0.225697 0.101653 0.327360 0.264593 0.136704 0.080702 0.154987 0.007247 1.000000